# -*- coding: utf-8 -*-

from wxgame import db
from . import ts_func


class Robot(db.Model):
    __tablename__ = 'robot'

    wxid = db.Column(db.String(32), primary_key=True)
    alias = db.Column(db.String(128))
    nickname = db.Column(db.String(128))
    default_role = db.Column(db.Integer, default=0)
    queue_name = db.Column(db.String(128))
    # 0: offline 1: online -1: disconnected 2: ping_i pass
    status = db.Column(db.Integer, nullable=False, default=1)
    create_time = db.Column(db.Integer, nullable=False, default=ts_func)

    rooms = db.relationship(
        'RoomRobot',
        backref=db.backref('robot', lazy='joined'),
        lazy='dynamic'
    )

    def __repr__(self):
        return '<Robot: wxid={}, alias={}, nickname={}>'.format(self.wxid, self.alias, self.nickname)
